package com.tianji.learning.controller;


import com.tianji.common.utils.BeanUtils;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.domain.query.PointsBoardQuery;
import com.tianji.learning.domain.vo.PointsBoardSeasonVO;
import com.tianji.learning.domain.vo.PointsBoardVO;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.tianji.learning.service.IPointsBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 学霸天梯榜 前端控制器
 * </p>
 *
 * @author huanghui
 * @since 2023-07-29
 */
@RestController
@RequestMapping("/boards")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "积分相关接口")
public class PointsBoardController {

    private final IPointsBoardService pointsBoardService;

    private  final IPointsBoardSeasonService seasonService;

    /** @author ZXX-挚爱
    * @Description 分页查询指定赛季的积分排行榜
    * @Dete 3:56 2023/8/1
    * @Param [query]
    * @return com.tianji.learning.domain.vo.PointsBoardVO
    **/

    @GetMapping
    @ApiOperation("分页查询指定赛季的积分排行榜")
    public PointsBoardVO queryPointsBySeason(PointsBoardQuery query){
        return pointsBoardService.queryPointsBoardBySeason(query);
    }

    /** @author ZXX-挚爱
    * @Description 查询赛季信息列表
    * @Dete 1:56 2023/8/1
    * @Param []
    * @return java.util.List<com.tianji.learning.domain.vo.PointsBoardSeasonVO>
    **/

    @ApiOperation("查询赛季信息列表")
    @GetMapping("/seasons/list")
    public List<PointsBoardSeasonVO> queryPointsBoardSeasons(){
        log.info("查询赛季信息列表");
        //1.获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //2.查询赛季数据
        List<PointsBoardSeason> list = seasonService.lambdaQuery().le(PointsBoardSeason::getBeginTime, now).list();
        if (CollUtils.isEmpty(list)) {
            return CollUtils.emptyList();
        }
        //3.返回VO实体
        return BeanUtils.copyToList(list, PointsBoardSeasonVO.class);
    }
}
